<template>
  <div>
    <div class="female">女生</div>
    <p id="typefemale">作品类型</p>
    <ul id="type">
      <li v-for="item in type" :key="item.id" @click="send(item.major)">
        {{item.major}}
        &nbsp;&nbsp;
      </li>
    </ul>
    <div class="bigbox">
      <div class="box" v-for="item in book" :key="item.id">
        <img class="img" :src="`http://statics.zhuishushenqi.com`+`${item.cover}`" alt />
        <div class="right">
          <p class="p1" @click="resive(item._id)">{{item.title}}</p>
          <p class="p2">
            <span class="s1" @click="jump(item.author)">{{item.author}}</span>
            <!-- <span class="s1">{{item.author}}</span> -->
            <span>&nbsp;|&nbsp;</span>
            <span class="s2" @click="jump(item.majorCate)">{{item.majorCate}}</span>
          </p>
          <p class="s3">{{item.shortIntro}}</p>
          <p class="p3">
            <span class="s1">
              人气:
              <span class="x2">{{item.latelyFollower}}</span>
            </span>
            <span>&nbsp;|&nbsp;</span>
            <span class="s2">
              读者留存:
              <span class="x1">{{item.retentionRatio}}%</span>
            </span>
          </p>
        </div>
      </div>
    </div>
    <!-- 分页器 -->
    <div class="pagination">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        layout=" prev, pager, next"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import { getlistcat } from "../../api/wwj/index";
import { getlistcatdetail } from "../../api/wwj/index";
export default {
  data() {
    return {
      type: [],
      book: [],
      total: 0,
      oldBook: []
    };
  },
  created() {
    this.updatastulist();
  },
  mounted() {
    getlistcatdetail("古代言情").then(res => {
      this.book = res.data.books.slice(0, 8);

      this.oldBook = res.data.books;

      this.total = res.data.books.length;
    });
  },
  methods: {
    updatastulist(params = {}) {
      getlistcat(params)
        .then(res => {
          console.log(res.data.female);
          this.type = res.data.female;
        })
        .catch(err => {
          alert("错误");
        });
    },
    handleCurrentChange(pageNum) {
      let start = (pageNum - 1) * 8;
      let end = pageNum * 8;
      this.book = this.oldBook.slice(start, end);
    },
    send(major) {
      getlistcatdetail(major).then(res => {
        this.book = res.data.books.slice(0, 8);

        this.oldBook = res.data.books;

        this.total = res.data.books.length;
      });
    },
    jump(idse) {
      this.$router.push({ path: "/search", query: { id: idse } });
    },
    resive(_id) {
      localStorage.setItem("_id", _id);
      this.$router.push("/bookdetails");
    }
  }
};
</script>
<style scoped>
.female {
  text-align: left;
  font-size: 30px;
  color: royalblue;
  height: 50px;
}
#typefemale {
  text-align: left;
  color: royalblue;
  height: 50px;
  line-height: 50px;
}
#type {
  overflow: hidden;
}
#type > li {
  float: left;
}
h1 {
  padding-left: 18px;
  text-align: left;
}
.bigbox,
.box {
  display: flex;
  justify-content: space-between;
  text-align: left;
}
.bigbox {
  width: 900px;
  flex-wrap: wrap;
  border-left: 1px solid;
}
.box {
  margin: 20px 20px;
}
.img {
  width: 80px;
  height: 100px;
}
.right {
  width: 300px;
  height: 100px;
  display: block;
  padding-left: 25px;
}
p {
  display: block;
}
.p1 {
  font-size: 18px;
  line-height: 24px;
  cursor: pointer;

  font-weight: 600;
}
.p2 {
  line-height: 28px;
  color: #a1a5a1;
}
.s3 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  margin-top: 10px;
}
.s1,
.s2 {
  font-size: 12px;
  cursor: pointer;
}

.x2 {
  color: red;
}
.x1 {
  color: red;
}

li {
  cursor: pointer;
}
li:hover {
  font-weight: 800;
}
</style>
